package com.chat.datea.utils.fragment;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

/**
 * Created by dllo on 15/10/24.
 */
public class ReplaceFragment {

    /***
     * 谢彦斌 10.24
     *
     * @param containerViewId  需要替换的占位符id
     * @param fragment         要显示的fragment
     * @param isAddToBackStack 是否加入返回栈中
     * @param manager          管理者
     * @param name             fragment在返回栈的名称
     */
    public ReplaceFragment(Fragment fragment, FragmentManager manager, int containerViewId, boolean isAddToBackStack, String name) {
        FragmentTransaction transaction = manager.beginTransaction();
        transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        transaction.replace(containerViewId, fragment);
        if (isAddToBackStack) {
            //调用addToBackStack将Fragment添加到栈中
            transaction.addToBackStack(name);
        }

        transaction.commit();
    }
}
